<!--# layout("/templates/layout/layout_main.html",{"title":"用户管理","nameSpace":"user_admin","breadcrumbs":[{"name":"用户管理"}]}){ #-->
	<!--# var pager = obj.data.pager ; #-->
	<table id="listTable" class="table  table-hover general-table table-striped table-bordered no-margin-bottom">
		<thead>
			<tr>
				<th colspan="9">
					<div class="row">
						<div class="col-md-3 ">
							<form action="${base}/user/list" method="post" class="search-form">
								<div class="input-group">
									<span class="input-group-addon">关键字</span> <input type="text" class="form-control" placeholder="请输入关键词进行检索..." style="font-weight: 500" name="key"
										value="${obj.data.pager.params.key}" data-default="Search..." data-error="请输入搜索关键词" placeholder="请输入角色名检索">
									<span class="input-group-addon search-btn" style="cursor: pointer;"><i class="fa fa-search"></i> GO</span>
								</div>
							</form>
						</div>
						<div class="col-md-2 col-md-offset-7">
							<a href="${base}/user/edit" data-toggle="modal" class="btn btn-info btn-sm"><i class="fa fa-plus-circle"></i> 添加用户</a>
						</div>
					</div>
				</th>
			</tr>
			<tr>
				<th class="center" style="width:35px;">
					<label class="pos-rel"><input type="checkbox" class="ace checkbox checkall" /><span class="lbl"></span></label>
				</th>
				<th class="center">序号</th>
				<th class="center">登录名</th>
				<th class="center">真实姓名</th>
				<th class="center hidden-phone">联系电话</th>
				<th class="center">Email</th>
				<th class="center">创建时间</th>
				<th class="center">状态</th>
				<th class="center">操作</th>
			</tr>
		</thead>
		<tbody>
			<!--# if(pager.pageRows.~size > 0){ #-->
				<!--# for(user in pager.pageRows){ #-->
				<tr>
					<td  class="center">
						<label><input type='checkbox' name='ids' value="${user.id}" class="ace checkbox"/><span class="lbl"></span></label>
					</td>
					<td  class="center">${(pager.pageNumber - 1)*pager.pageSize + userLP.index}</td>
					<td  class="center">${user.name}</td>
					<td  class="center">${user.realName}</td>
					<td  class="center">${user.phone}</td>
					<td  class="center">${user.email}</td>
					<td  class="center">${user.createTime, dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
					<td  class="center">
					<!--# if(user.status == 'ACTIVED'){ #-->
						<span class="label label-sm label-success">${user.status.name}</span>
					<!--# }else if(user.status == 'DISABLED'){ #-->
						<span class="label label-sm label-warning">${user.status.name}</span>
					<!--# } #-->
					</td>
					<td class="center">
						<div class="hidden-sm hidden-xs btn-group">
							<a class="btn btn-xs btn-success" title="角色权限" href="javascript:editUserRole(${user.id!})">
								<i class="ace-icon fa fa-cogs bigger-120" title="角色权限"></i>
							</a>
							<a class="btn btn-xs btn-warning" title="编辑" href="${base!}/user/edit?id=${user.id!}">
								<i class="ace-icon fa fa-pencil-square-o bigger-120" title="编辑"></i>
							</a>
							<a class="btn btn-xs btn-danger" title="删除" onclick="toDel('${user.id}');">
								<i class="ace-icon fa fa-trash-o bigger-120" title="删除"></i>
							</a>
						</div>
					</td>
				</tr>
				<!--# } #-->
			<!--#}else{ #-->
				<tr class="main_info">
					<td colspan="9" class="center">没有相关数据</td>
				</tr>
			<!--# } #-->
		</tbody>
	</table>
	<div style="padding-right:40px;">
		<div class="hr-6"></div>
		<ul class='pagination'></ul>
	</div>
	<div>&nbsp;</div>
	<div class="" id="dialogs">
		<div id="roleDialog" style="padding:10px;padding-left:20%;"  class="hidden">
			<div id="roleTree"></div>
		</div>
	</div>
<script type="text/javascript">
	$(function($) {
		
		$('.pagination')._pagination({pn:${obj.data.pager.pageNumber},ps:${obj.data.pager.pageSize},total:${obj.data.pager.recordCount}});
		
		/**
			角色树初始化
		*/
		$('#roleTree').ace_tree({
			dataSource: initTreeData,
			multiSelect: true,
			cacheItems: true,
			'open-icon' : 'ace-icon tree-minus',
			'close-icon' : 'ace-icon tree-plus',
			'selectable' : true,
			'selected-icon' : 'ace-icon fa fa-check',
			'unselected-icon' : 'ace-icon fa fa-times',
			loadingHTML : '<div class="tree-loading"><i class="ace-icon fa fa-refresh fa-spin blue"></i></div>'
		}).on('selected.fu.tree', function(e, options) {
			var uid = $('#roleTree').data('uid');
			var rid = options.target.additionalParameters.id;
			$.post(getRootPath() + '/user/setRole', {uid:uid,rid:rid,op:'true'}, function(r) {
				if (r.operationState == 'SUCCESS') {
					
				} else {
					layer.msg(r.data.reason);
				}
			});
		}).on('loaded.fu.tree', function(e) {
		}).on('deselected.fu.tree', function(e, options) {
			var uid = $('#roleTree').data('uid');
			var rid = options.target.additionalParameters.id;
			$.post(getRootPath() + '/user/setRole', {uid:uid,rid:rid,op:'false'}, function(r) {
				if (r.operationState == 'SUCCESS') {
					
				} else {
					layer.msg(r.data.reason);
				}
			});
		});
		
	});
	
	/**
	 移除用户
	*/
	function toDel(uid){
		if(uid == ''){
			return;
		}
		layer.confirm('确定要删除该用户？',function(){
			$.post(getRootPath() + '/user/del', {id:uid}, function(r) {
				if (r.operationState == 'SUCCESS') {
					$('.search-btn').click();
				} else {
					layer.msg(r.data.reason);
				}
			}, 'json');
		});
	}
	
	/**
	* 角色设置
	*/
	function editUserRole(uid){
		if(!uid){
			return;
		}
		layer.open({
		  type: 1,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['320px', '340px'], //宽高
		  content: $('#roleDialog')
		});
		$("#roleDialog").removeClass("hidden");
		$("#roleTree li.tree-item").removeClass("tree-selected").each(function(){
			$(this).find('i.fa-check').removeClass("fa-check").addClass("fa-times")
		});
		$("#roleTree i.tree-plus").trigger("click");
		//加载用户的角色
		$.post(getRootPath() + '/role/userRole',{uid:uid},function(r){
			if(r.operationState == 'SUCCESS'){
				$('#roleTree').data("uid", uid); 
				$('#roleTree .tree-item').each(function(i, dom){
					var treeObj = $(dom).data(),roleObj;
					if("additionalParameters" in treeObj){
						for(var i in r.data.roles){
							roleObj = r.data.roles[i];
							if(roleObj.id == treeObj.additionalParameters.id){
								//$(dom).trigger("click");
								$(dom).addClass("tree-selected").find("i.fa-times").removeClass("fa-times").addClass("fa-check");
							}
						}
					}
					
				});
			}
		})
	}
	
	/**
	*
	*加载角色数据
	*/
	function initTreeData(options,callback){
		var $data = [{text:"全部角色", type:"folder",additionalParameters:{parent:"root"}}];
		if("additionalParameters" in options && options.additionalParameters.parent == "root" ){
			$.post(getRootPath() + '/role/all',{},function(r){
				if(r.operationState == 'SUCCESS'){
					var arr = new Array(),adds = new Object();
					$.each(r.data.roles, function(i,obj){
						adds = new Object();
						adds.name = obj.name ;
						adds.type = "item";
						adds.additionalParameters = obj ;
						arr.push(adds);
					});
					callback({ data: arr});
				}
			});
		}else{
			if($data != null)//this setTimeout is only for mimicking some random delay
				setTimeout(function(){callback({ data: $data });} , parseInt(Math.random() * 500) + 200);
		}

	}
</script>
<!--# } #-->


 